package com.xpalive.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {

    private final ExecutorService executorService;

    public ThreadPool(){
        this(100, 1000);
    }

    public ThreadPool(int maxPoolSize, int maxQueueSize) {
        this.executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
            maxPoolSize, 120L, TimeUnit.MINUTES, new ArrayBlockingQueue<>(maxQueueSize));
    }

    public void execute(Runnable task) {
        executorService.execute(task);
    }
}